<template>
	<view class="content" style="height: 100vh;">
		<uni-list :border="true">
			<view v-if="loading" class="loading"><text>加载中...</text></view>
			<m-empty-data v-else-if="data.length == 0" noTxt="暂无记录"></m-empty-data>
			<uni-list-chat v-for="(item, index) in data" :key="index" title="系统通知" avatar="/static/img/logo.png"
				:note="item.content" :time="formatCreateTime(item.time)"
				:clickable="clickable" badge-positon="left" badge-text="dot" :showBadge="item.isRead"></uni-list-chat>
		</uni-list>
	</view>
</template>

<script>
	import {
		mapMutations,
		mapGetters,
		mapState
	} from 'vuex';
	import mEmptyData from '@/components/m-empty-data/m-empty-data.vue';
	import {
		formatDate
	} from '@/common/date';
	export default {
		components: {
			mEmptyData
		},
		computed: {
			...mapGetters({
				currentUser: 'user/info',
				hasLogin: 'user/hasLogin'
			}),
			...mapState(['userInfo']),
		},
		data() {
			return {
				clickable: true,
				unreadTotal: 0,
				where: {},
				data: [],
				loading: false,
			};
		},
		onPullDownRefresh() {
			console.log('---onPullDownRefresh---');
		},
		onReachBottom() {
			console.log('---onReachBottom---');
		},
		onLoad() {
			console.log("系统消息页面打开了")
		this.getNoticeList();
		},
		onShow() {},

		methods: {
			async getNoticeList() {
				let param = {
					"userName": this.userInfo.nickname
				};
				console.log("登录信息",this.userInfo)
				if (!this.userInfo.nickname) {
					uni.showToast({
						title: "请登录后获取",
						icon: "none",
						duration: 2000
					})
				}
				let res = await this.$apis.getCmsList(param);
				if (res.data.length > 0) {
					this.data = res.data;
				}
			},

			toDetail(item) {
				this.$mRouter.push({
					route: this.$mRoutesConfig.noticeDetail,
					query: {
						item: encodeURIComponent(JSON.stringify(item))
					}
				});
			},

			formatCreateTime(time) {
				if (time == null || time === '') {
				        return null;
				    }
				    // 直接将 ISO 格式的时间字符串转换为 Date 对象
				    let date = new Date(time);
				    // 调用 formatDate 函数，格式化为 "yyyy-MM-dd HH:mm:ss"
				    return formatDate(date, 'yyyy-MM-dd HH:mm:ss');
			},
		}
	};
</script>

<style lang="scss">
	.loading {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-top: 20upx;

		text {
			color: $font-color-666;
		}
	}
</style>